import { message } from 'antd';
import { fetchDetail,handleDeliverGoods } from '../services/api';

const OrderModel = {
  namespace: 'orderLook',
  state: {
    pageInfoDetail: {},
    code:null,
  },
  effects: {

    // 获取详情
    * fetchDetail({ payload }, { call, put }) {
      const response = yield call(fetchDetail, payload);
      if (response.code !== '0') {
        message.error(response.msg);
      }
      yield put({
        type: 'updateState',
        payload: {
          pageInfoDetail: response.result,
        },
      });
    },

    // 处理确认发货
    * handleDeliverGoods({ payload }, { call, put }) {
      const response = yield call(handleDeliverGoods, payload);
      if (response.code !== '0') {
        message.error(response.msg);
      }
      yield put({
        type: 'updateState',
        payload: {
          code: response,
        },
      });
    },

  },
  reducers: {
    updateState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },

  },
};
export default OrderModel;
